import Foundation

struct AddressResponse: Codable{
    let data: [AddressData]
}
struct DefaultAddressResponse: Codable{
    let data: AddressData
}
struct AddressData: Codable {
    let id: String
    let name: String
    let mobile: String
    let addressPath: String
    let addressPathDes: String
    let detailAddress: String
    let defaultSelected: Int  // 直接用 Int 存储

    var isDefault: Bool {
        return defaultSelected == 1
    }
    
}

struct Decoder{
    static func data<T: Codable>(_ jsonString: String?) -> T? {
        guard let jsonData = jsonString?.data(using: .utf8) else { return nil }
        do {
            let decodedResponse = try JSONDecoder().decode(T.self, from: jsonData)
            return decodedResponse
        } catch {
            print("JSON 解析失败: \(error)")
            return nil
        }
    }
}

struct RegionInfoData: Codable{
    let data: [RegionInfo]
}
struct RegionInfo: Codable{
    let code: String
    let parentCode: String
    let level: Int
    let name: String
    let childrenList: [RegionInfo]?
}
